package com.example.LibrarySystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.LibrarySystem.pojo.Borrowing;
import com.example.LibrarySystem.pojo.dto.BorrowingDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.*;

@Mapper
public interface BorrowingMapper extends BaseMapper<Borrowing> {
    /**
     * 该报错不用管
     * @param bookName
     * @param userName
     * @param userSno
     * @return
     */
    public List<Map<String,Object>> getBorrowByInfoPages(@Param("bookName") String bookName,
                                              @Param("userName") String userName,
                                              @Param("userSno") String userSno,
                                              @Param("start")Integer start,
                                              @Param("pages")Integer pages);

    public List<Map<String,Object>> getBorrowByInfoNoPages(@Param("bookName") String bookName,
                                                         @Param("userName") String userName,
                                                         @Param("userSno") String userSno);

    @Update("update borrowing set return_date = #{date}, is_return = 1,status = 1 where id = #{id}")
    public int returnBooks(int id, Date date);

    /**
     * 查询以当天的一周的数据
     * @return
     */
    @Select("SELECT book_id,count(book_id) as number FROM borrowing WHERE borro_date >= CURDATE() - INTERVAL 1 WEEK group by book_id")
    public List<Map<String,Object>> week();

    /**
     * 查询以当天的一月的数据
     * @return
     */
    @Select("SELECT book_id,count(book_id) as number FROM borrowing WHERE borro_date >= CURDATE() - INTERVAL 1 MONTH group by book_id")
    public List<Map<String,Object>> month();
}
